package com.bookmall.product.controller;

import java.util.List;

import com.bookmall.common.utils.PageUtils;
import com.bookmall.product.domain.vo.BookBuyVo;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.log.annotation.Log;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.core.web.controller.BaseController;
import com.bookmall.product.domain.BookBuy;
import com.bookmall.product.service.IBookBuyService;

/**
 * 求购信息Controller
 * 
 * @author 胡菜鸡
 * @date 2022-03-13
 */
@RestController
@RequestMapping("/product/buyBook")
public class BookBuyController extends BaseController {

    @Autowired
    private IBookBuyService bookBuyService;

    /**
     * 查询求购信息列表
     */
    @PreAuthorize("@ss.hasPermi('product:buyBook:list')")
    @GetMapping("/list")
    public AjaxResult list(BookBuy bookBuy)
    {
        PageUtils page = bookBuyService.selectBookBuyList(bookBuy);
        return AjaxResult.success(page);
    }

//    /**
//     * 导出求购信息列表
//     */
//    @PreAuthorize("@ss.hasPermi('product:buyBook:export')")
//    @Log(title = "求购信息", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, BookBuy bookBuy)
//    {
//        List<BookBuy> list = bookBuyService.selectBookBuyList(bookBuy);
//        ExcelUtil<BookBuy> util = new ExcelUtil<BookBuy>(BookBuy.class);
//        util.exportExcel(response, list, "求购信息数据");
//    }
//
    /**
     * 获取求购信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('product:buyBook:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(bookBuyService.selectBookBuyById(id));
    }

    /**
     * 新增求购信息
     */
    @PreAuthorize("@ss.hasPermi('product:buyBook:add')")
    @Log(title = "求购信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BookBuyVo bookBuyVo)
    {
        return toAjax(bookBuyService.insertBookBuy(bookBuyVo));
    }

    /**
     * 修改求购信息
     */
    @PreAuthorize("@ss.hasPermi('product:buyBook:edit')")
    @Log(title = "求购信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BookBuyVo bookBuyVo)
    {
        return toAjax(bookBuyService.updateBookBuy(bookBuyVo));
    }

    /**
     * 改变求购信息状态
     */
    @PreAuthorize("@ss.hasPermi('product:buyBook:edit')")
    @Log(title = "求购信息", businessType = BusinessType.UPDATE)
    @PutMapping("/changeStatus")
    public AjaxResult changeStatus(@RequestBody BookBuy bookBuy)
    {
        return toAjax(bookBuyService.updateBuyStatus(bookBuy));
    }

    /**
     * 删除求购信息
     */
    @PreAuthorize("@ss.hasPermi('product:buyBook:remove')")
    @Log(title = "求购信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable List<String> ids)
    {
        return toAjax(bookBuyService.deleteBookBuyByIds(ids));
    }
}
